package extras.mak001;

import java.util.ArrayList;

import org.rsbuddy.widgets.Bank;

import com.rsbuddy.script.wrappers.Item;

public class BankCache {

	private ArrayList<Integer> ids = new ArrayList<Integer>();
	private ArrayList<String> names = new ArrayList<String>();
	private ArrayList<Integer> stacksizes = new ArrayList<Integer>();

	public int getAmount() {
		return ids.size();
	}

	public boolean hasItem(int id) {
		return ids.contains(id);
	}

	public boolean hasItem(int id, int stacksize) {
		if (!ids.contains(id)) {
			return false;
		}
		int pos = ids.indexOf(id);
		return stacksizes.get(pos) >= stacksize;
	}

	public boolean hasItem(String s) {
		return names.contains(s);
	}

	public boolean hasItem(String s, int stacksize) {
		if (!names.contains(s)) {
			return false;
		}
		int pos = names.indexOf(s);
		return stacksizes.get(pos) >= stacksize;
	}

	public Integer[] getIds() {
		return ids.toArray(new Integer[ids.size()]);
	}

	public String[] getNames() {
		return names.toArray(new String[names.size()]);
	}

	public Integer[] getStackSizes() {
		return stacksizes.toArray(new Integer[stacksizes.size()]);
	}

	public int getIndex(String s) {
		return names.indexOf(s);
	}

	private boolean b;

	public void update() {
		ids.clear();
		names.clear();
		Item[] items = Bank.getItems();
		for (Item i : items) {
			ids.add(i.getId());
			names.add(i.getName().replaceAll("<.*>", ""));
			stacksizes.add(i.getStackSize());
			if (b != true) {
				b = true;
			}
		}
	}

	public boolean didUpdate() {
		return b;
	}

}
